<template>
    <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <a-col :span="6" :sm="6">
                        <a-form-item label="年度">
                            <!-- <a-date-picker v-model="queryParam.shijian" /> -->
                            <a-date-picker 
                                style="width:100%"
                                :open='yearShowOne' 
                                @openChange="openChangeOne" 
                                @panelChange="panelChangeOne"  
                                mode="year" 
                                format="YYYY" 
                                type="date" 
                                :default-value="moment(new Date(), 'YYYY')" 
                                v-model="queryParam.shijian" 
                                suffix-icon=" " 
                                placeholder="年份"
                            />
                        </a-form-item>
                    </a-col>
                    
                    <a-col :span="6" :sm="6">
                        <a-form-item label="复审分组">
                            <a-select v-model="queryParam.fzid" placeholder="请选择复审分组" @change="handleSelectFz">
                                <a-select-option v-for="item in fzList" :key="item.id" :value="item.id">
                                    {{item.fs_fz_mc}}
                                </a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :md="6" :sm="8">
                        <a-form-item label="专家姓名">
                            <!-- <a-input placeholder="请填写专家姓名" v-model="queryParam.zjid"></a-input> -->
                            <a-select v-model="queryParam.zjid" placeholder="请选择专家" @change="handleSelectExpert($event)">
                                <a-select-option v-for="(item, index) in expertList" :key="index" :value="item.id">
                                    {{item.zj_xm}}
                                </a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :span="6" :sm="6">
                        <a-form-item label="答辩时间">
                            <a-select v-model="queryParam.dbsj" placeholder="请选择答辩时间">
                                <a-select-option v-for="(item,index) in cxjfsDbsjlist" :key="index" :value="item.id">
                                    {{item.fs_sj_rq}}{{item.fs_sj_sxw}}
                                </a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :md="10" :sm="12">
                        <a-form-item label="">
                            <a-button style="margin-right:10px;" type="primary" @click="searchQuery" icon="search">查询</a-button>
                            <a-button style="margin-right:10px;" type="primary" @click="searchReset" icon="reload">重置</a-button>
                            <a-button style="margin-right:10px;" v-print="'#j-table-force-nowrap'" type="primary" icon="download">打印</a-button>
                            <a-button type="primary" @click="handleExport" icon="search">导出</a-button>
                        </a-form-item>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <!-- 查询区域-END -->
        <!-- 操作按钮区域 高级查询区域-->
        <div class="table-operator" style="display: flex; align-items: center;justify-content: space-between;"></div>
        <!-- table区域-begin -->
        <div id="j-table-force-nowrap">
            <h2 style="text-align:center;font-size: 20px;">
                专家复审评分汇总表
                <!-- {{new Date().getFullYear()}}年度电力创新奖项目复审意见表(技术类) -->
            </h2>
            <p style="text-align:right;">
                <span style="margin-right:20px;">评审专家：{{zjxm}}</span>
                <span>日期：{{nowDate}}</span>
            </p>
            <a-table
                ref="table"
                size="middle"
                :scroll="{x: '100%'}"
                bordered
                rowKey="cxj_xmbh"
                :columns="columns"
                :dataSource="dataSource"
                :pagination="false"
                :loading="loading"
                class="j-table-force-nowrap"
                @change="handleTableChange">
            </a-table>
            <p style="text-align:right;margin-right:100px;padding-top:10px;">评审专家签字：</p>
        </div>
        <cxj-jscs-pf-js-modal ref="modalForm" @ok="modalFormOk"></cxj-jscs-pf-js-modal>
    </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import CxjJscsPfJsModal from './modules/CxjJscsPfJsModal'
import { getAction,postAction } from '../../api/manage'
import qs from 'qs';
import Vue from 'vue';
import moment from 'moment';
import { USER_INFO, ACCESS_TOKEN } from "@/store/mutation-types"
import {
    // 专家复审评分列表 - 信息化类
    cxjfsFspfListZjXxh
} from  "@/api/api";
import {
    cxjfs_fspsExport_xxh
} from "@/api/manage"
export default {
    name: 'CxjJscsPfJsList',
    // mixins:[JeecgListMixin, mixinDevice],
    mixins:[mixinDevice],
    components: {
        CxjJscsPfJsModal
    },
    data () {
        return {
            nowDate: '',
            timer: '',
            zjxm:"",
            fzid: "",
            fzList: [],
            expertList: [],
            cxjfsDbsjlist: [],
            queryParam: {
                shijian: null
            },

            cacheData: [],
            description: '初审项目评分表-技术类-获取分组项目',
            // 表头
            columns: [
                /** 
                 * 成果陈述 3分 fs_xmcs
                 * 专家提问及应答 2分 fs_zjtw
                 * 创新性 25分 fs_cxx
                 * 技术先进性及技术难度 25分 fs_xjx
                 * 项目实施效果 20分 fs_ssxg
                 * 项目社会及经济效益 15分 fs_jjxy
                 * 可操作性及推广价值 10分 fs_tgjz
                */
                {
                    title: '序号',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: '4%',
                    customCell: () => {
                        return {
                            style: {
                                'min-width': '40px',
                            },
                        };
                    },
                    align:"center",
                    // fixed: 'left',
                    customRender:function (t,r,index) {
                        return parseInt(index)+1;
                    }
                },
                
                {
                    title: '答辩时间',
                    align: "center",
                    dataIndex: 'dbsj',
                    width: '8%',
                    customCell: () => {
                        return {
                            style: {
                                'min-width': '80px',
                            },
                        };
                    },
                },
                
                {
                    title: '答辩序号',
                    align: "center",
                    dataIndex: 'xm_xh',
                    width: '6%',
                    scopedSlots: { customRender: '' },
                    customCell: () => {
                        return {
                            style: {
                                'min-width': '80px',
                            },
                        };
                    },
                },
                {
                    title: '成果编号',
                    align: "center",
                    dataIndex: 'cxj_xmbh',
                    width: '8%',
                    // scopedSlots: { customRender: 'cxj_xmbh' },
                    customCell: () => {
                        return {
                            style: {
                                'min-width': '80px',
                            },
                        };
                    },
                },
                {
                    title: '审查意见',
                    // width: 800,
                    align: 'center',
                    children: [
                        {
                            title: '成果陈述',
                            align: "center",
                            width: '6%',
                            customCell: () => {
                                return {
                                    style: {
                                        'min-width': '100px',
                                    },
                                };
                            },
                            children: [{
                                title: "3分",
                                align:"center",
                                width: '6%',
                                customCell: () => {
                                    return {
                                        style: {
                                            'min-width': '100px',
                                        },
                                    };
                                },
                                dataIndex: "fs_xmcs",
                                scopedSlots: { customRender: 'fs_xmcs' }
                            }]
                        },{
                            title: '专家提问及应答',
                            align: "center",
                            width: '7%',
                            customCell: () => {
                                return {
                                    style: {
                                        'min-width': '100px',
                                    },
                                };
                            },
                            children: [{
                                title: "2分",
                                align:"center",
                                width: '7%',
                                customCell: () => {
                                    return {
                                        style: {
                                            'min-width': '100px',
                                        },
                                    };
                                },
                                dataIndex: "fs_zjtw",
                                scopedSlots: { customRender: 'fs_zjtw' }
                            }]
                        },
                        {
                            title: '创新性',
                            align: "center",
                            width: '6%',
                            customCell: () => {
                                return {
                                    style: {
                                        'min-width': '100px',
                                    },
                                };
                            },
                            children: [{
                                title: "25分",
                                align:"center",
                                width: '6%',
                                customCell: () => {
                                    return {
                                        style: {
                                            'min-width': '100px',
                                        },
                                    };
                                },
                                dataIndex: "fs_cxx",
                                scopedSlots: { customRender: 'fs_cxx' }
                            }]
                        },
                        {
                            title: '技术先进性及技术难度',
                            align: "center",
                            width: '9%',
                            customCell: () => {
                                return {
                                    style: {
                                        'min-width': '100px',
                                    },
                                };
                            },
                            children: [{
                                title: "25分",
                                align:"center",
                                width: '9%',
                                customCell: () => {
                                    return {
                                        style: {
                                            'min-width': '100px',
                                        },
                                    };
                                },
                                dataIndex: "fs_xjx",
                                scopedSlots: { customRender: 'fs_xjx' }
                            }]
                        },
                        {
                            title: '项目实施效果',
                            width: '6%',
                            customCell: () => {
                                return {
                                    style: {
                                        'min-width': '100px',
                                    },
                                };
                            },
                            children: [{
                                title: "20分",
                                align:"center",
                                width: '6%',
                                customCell: () => {
                                    return {
                                        style: {
                                            'min-width': '100px',
                                        },
                                    };
                                },
                                dataIndex: "fs_ssxg",
                                scopedSlots: { customRender: 'fs_ssxg' }
                            }]
                        },
                        {
                            title: '项目社会及经济效益',
                            align: "center",
                            width: '7%',
                            customCell: () => {
                                return {
                                    style: {
                                        'min-width': '100px',
                                    },
                                };
                            },
                            children: [{
                                title: "15分",
                                align:"center",
                                width: '7%',
                                customCell: () => {
                                    return {
                                        style: {
                                            'min-width': '100px',
                                        },
                                    };
                                },
                                dataIndex: "fs_jjxy",
                                scopedSlots: { customRender: 'fs_jjxy' }
                            }]
                        },
                        {
                            title: '可操作性及推广价值',
                            width: '7%',
                            customCell: () => {
                                return {
                                    style: {
                                        'min-width': '100px',
                                    },
                                };
                            },
                            children: [{
                                title: "10分",
                                align:"center",
                                width: '7%',
                                customCell: () => {
                                    return {
                                        style: {
                                            'min-width': '100px',
                                        },
                                    };
                                },
                                dataIndex: "fs_tgjz",
                                scopedSlots: { customRender: 'fs_tgjz' }
                            }]
                        },
                        {
                            title: '评审意见',
                            dataIndex: 'fs_pingshenyj',
                            scopedSlots: { customRender: 'fs_pingshenyj' }
                        },
                        {
                            title: '合计',
                            align: "center",
                            width: '6%',
                            customCell: () => {
                                return {
                                    style: {
                                        'min-width': '60px',
                                    },
                                };
                            },
                            dataIndex: 'fs_zongfen',
                            scopedSlots: { customRender: 'fs_zongfen' },
                            sorter: (a, b) => b.fs_zongfen - a.fs_zongfen,
                        },
                    ]
                },
            ],
            url: {
                fzlist: "/cxj/cxjFsFz/cxjfs_fzlist",
                list: "/cxj/cxjFsPfJs/cxjfs_fspfListZj",
                delete: "/cxj/cxjJscsPfJs/delete",
                deleteBatch: "/cxj/cxjJscsPfJs/deleteBatch",
                exportXlsUrl: "/cxj/cxjJscsPfJs/exportXls",
                importExcelUrl: "cxj/cxjJscsPfJs/importExcel",
                // 已选专家
                cxjfsFzzjlistYx: 'cxj/cxjFsFzZj/cxjfs_fzzjlist_yx',
                // 答辩时间列表
                cxjfs_dbsjlist: '/cxj/cxjFsSj/cxjfs_getDbsjListByFzid'
            },
            superFieldList:[],
            editingKey: '',

            dictOptions:{},
            superFieldList:[],
            fileStatus: "",
            selectedRowKeys: [],
            selectionRows: [],
            loading: false,
            isorter: {
                column: 'createTime',
                order: 'desc',
            },
            dataSource: [],
            ipagination: {
                current: 1,
                pageSize: 10,
                pageSizeOptions: ['10', '20', '30'],
                showTotal: (total, range) => {
                return range[0] + "-" + range[1] + " 共" + total + "条"
                },
                showQuickJumper: true,
                showSizeChanger: true,
                total: 0
            },

            /* 年份参数开始 */
            yearShowOne:false,
            shijian: moment(new Date()).format('YYYY'),
            /* 年份参数结束 */

        }
    },
    created() {
        this.$set(this.dictOptions, 'isValid', [{text:'是',value:'Y'},{text:'否',value:'N'}])
        this.getSuperFieldList();
        this.getFzList();
        this.timer = setInterval(()=>{
            this.nowDate = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
        },1000)
    },
    methods: {
        moment,
        /* 获取分组 */
        getFzList(arg) {
            if (!this.url.fzlist) {
                this.$message.error("请设置url.fzlist属性!")
                return
            }
            getAction(this.url.fzlist,{flid:41}).then((res) => {
                if (res.success) {
                    this.fzList = res.result.records || res.result;
                    this.queryParam.fzid = res.result.records[0].id;
                    // this.loadData();
                    this.getExpertList(this.queryParam.fzid);
                    this.getDbTimeList();
                }
                if (res.code === 510) {
                    this.$message.warning(res.message)
                }
            })
        },
        // 获取答辩时间列表
        getDbTimeList(){
            console.log('分组id', this.queryParam.fzid)
            postAction(this.url.cxjfs_dbsjlist, qs.stringify({fzid: this.queryParam.fzid})).then((res) => {
                if (res.success) {
                    this.cxjfsDbsjlist = res.result.records || res.result;
                }
                if (res.code === 510) {
                    this.$message.warning(res.message)
                }
            })
        },
        // 切换分组
        handleSelectFz(value){
            this.queryParam.fzid = value;
            this.getExpertList(value);
            // console.log('切换分组',this.queryParam)
            // this.loadData(1);
        },
        // 根据分组获取专家列表
        getExpertList(id){
            getAction(this.url.cxjfsFzzjlistYx, {csfzid:id}).then((res) => {
                if (res.success) {
                    this.expertList = res.result.records || res.result;
                    this.queryParam.zjid = res.result[0].id;
                    this.zjxm = res.result[0].zj_xm;
                    this.loadData();
                }
                if (res.code === 510) {
                    this.$message.warning(res.message)
                }
            })
        },
        handleSelectExpert(value){
            console.log('专家id',value)
            console.log(this.expertList)
            this.queryParam.zjid = value;
            this.loadData()
            this.expertList.map(item=>{
                if (item.id == value) {
                    this.zjxm = item.zj_xm;
                }
            })
        },








        /* 年份控制开始 */
        openChangeOne(status){
            //status是打开或关闭的状态
            if(status){
                this.yearShowOne =  true;
            }
        },
        // 得到年份选择器的值
        panelChangeOne(value){
            // params.shijian = value;
            this.shijian = moment(value).format('YYYY');
            this.queryParam.shijian = this.shijian;
            this.yearShowOne = false
        },
        /* 年份控制结束 */

        /* 获取列表固定格式开始 */
        getQueryField() {
            //TODO 字段权限控制
            var str = "id,";
            this.columns.forEach(function (value) {
                str += "," + value.dataIndex;
            });
            return str;
        },
        // 获取分组项目
        loadData(arg) {
            if (arg === 1) {
                this.ipagination.current = 1;
            }
            this.loading = true;
            this.queryParam.shijian = this.shijian;
            cxjfsFspfListZjXxh(qs.stringify(this.queryParam)).then(res=>{
                if (res.success) {
                    this.dataSource = res.result.records || res.result;
                    if (res.result.total) {
                        this.ipagination.total = res.result.total;
                    } else {
                        this.ipagination.total = 0;
                    }
                }
                if (res.code === 510) {
                    this.$message.warning(res.message)
                }
                this.loading = false;
            })
        },
        onSelectChange(selectedRowKeys, selectionRows) {
            this.selectedRowKeys = selectedRowKeys;
            this.selectionRows = selectionRows;
        },
        onClearSelected() {
            this.selectedRowKeys = [];
            this.selectionRows = [];
        },
        modalFormOk() {
            // 新增/修改 成功时，重载列表
            this.loadData();
            //清空列表选中
            this.onClearSelected()
        },
        handleTableChange(pagination, filters, sorter) {
            //分页、排序、筛选变化时触发
            //TODO 筛选
            if (Object.keys(sorter).length > 0) {
                if (this.editingKey) {
                } else {
                    this.loadData();
                }
                this.isorter.column = sorter.field;
                this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
            } else {
                this.loadData();
            }
            this.ipagination = pagination;
            // this.loadData();
            // if (Object.keys(sorter).length > 0) {
            //     this.isorter.column = sorter.field;
            //     this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
            // }
            // this.ipagination = pagination;
            // this.loadData();
        },
        searchQuery() {
            this.loadData(1);
        },
        searchReset() {
            this.queryParam = {};
            this.shijian = moment(new Date()).format('YYYY');
            this.getFzList();
        },
        /* 获取列表固定格式结束 */

        /* 导出开始 */
        handleExport(){
            let that = this;
            let data = {
                shijian: this.shijian,
                fzid: this.queryParam.fzid,
                zjid: this.queryParam.zjid,
                dbsj: this.queryParam.dbsj
            }
            cxjfs_fspsExport_xxh(data).then(res=>{
                that.downfn('复审评分导出-信息化类',res);
            })
        },
        downfn(name, res) {
            const _res = res;
            let blob = new Blob([_res], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
            let downloadElement = document.createElement("a");
            let href = window.URL.createObjectURL(blob); //创建下载的链接
            downloadElement.href = href;
            downloadElement.download = name; //下载后文件名
            document.body.appendChild(downloadElement);
            downloadElement.click(); //点击下载
            document.body.removeChild(downloadElement); //下载完成移除元素
            window.URL.revokeObjectURL(href); //释放掉blob对象
        },
        /* 导出结束 */
        beforeDestroy() {
            if (this.timer) {
                clearInterval(this.timer)
            }
        },

        initDictConfig(){},
        getSuperFieldList(){
            let fieldList=[];
            fieldList.push({type:'string',value:'sysZjId',text:'专家ID',dictCode:''})
            fieldList.push({type:'string',value:'cxjCxjId',text:'成果ID',dictCode:''})
            fieldList.push({type:'double',value:'jscsCxx',text:'技术创新性',dictCode:''})
            fieldList.push({type:'double',value:'jscsXjx',text:'技术先进性',dictCode:''})
            fieldList.push({type:'double',value:'jscsSsxg',text:'实用化程度',dictCode:''})
            fieldList.push({type:'double',value:'jscsJjxy',text:'经济效益',dictCode:''})
            fieldList.push({type:'double',value:'jscsTgjz',text:'推动作用',dictCode:''})
            fieldList.push({type:'string',value:'jscsPingjiayj',text:'评审意见',dictCode:''})
            fieldList.push({type:'double',value:'jscsZongfen',text:'总分',dictCode:''})
            fieldList.push({type:'string',value:'jscsZt',text:'评分状态',dictCode:''})
            fieldList.push({type:'string',value:'shijian',text:'年度',dictCode:''})
            fieldList.push({type:'string',value:'bz1',text:'备注1',dictCode:''})
            fieldList.push({type:'string',value:'bz2',text:'备注2',dictCode:''})
            fieldList.push({type:'string',value:'bz3',text:'备注3',dictCode:''})
            fieldList.push({type:'switch',value:'isValid',text:'是否有效'})
            this.superFieldList = fieldList
        }
    }
}
</script>
<style scoped lang="less">
@import '~@assets/less/common.less';
@page {
    size: auto A4 landscape;
    margin: 3mm;
}
/deep/* {
  font-size: 14px;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
/deep/.ant-table-tbody > tr > td {
  word-break: break-all;
  white-space: normal;
  word-wrap:break-word;
  font-size:14px;
  padding:6px 3px!important;
}
/deep/.ant-table-tbody > tr > td > div {
  font-size: 14px;
}

/deep/.ant-table-thead > tr > th {
  word-break: break-all;
  white-space: normal;
  word-wrap:break-word;
  text-align: center;
  font-size:14px;
  padding:5px 3px!important;
}
.editable-row-operations a {
  margin-right: 8px;
}
.tjdata {
  // margin-top: 20px;
  span {
    margin-right:20px;
    line-height: 30px;
    font-size: 16px;
  }
}
.count {
  color: #ee9900;
  font-weight: 700;
  font-size: 16px;
}
/deep/.ant-table-tbody > tr > td:nth-child(13) {
  color: #ee9900!important;
  font-weight: 700;
  font-size: 16px;
}
.editable-row-operations a {
  margin: 0px 2px;
}
  .table-page-search-wrapper .anty-form-btn .ant-form-item {
    margin-bottom: 10px;
  }
</style>